import { BasicColumn, FormSchema } from '@/components/Table';
import { h } from 'vue';
import { Tag } from 'ant-design-vue';
import Icon from '@/components/Icon/Icon.vue';
import { getMenuTreeList } from '@/api/demo/system';
import { VxeGridPropTypes } from '@/components/VxeTable';

export const columns: BasicColumn[] = [
  {
    title: '链路名称',
    dataIndex: 'name',
    width: 150,
    customRender: ({ record }) => {
      const lineType = record.lineType;
      let text = '';
      if (lineType == 1) {
        text = `条件${record.sort}`;
      } else {
        text = '无条件进入此节点';
      }
      return text;
    },
  },
  {
    title: '发起类型',
    dataIndex: 'conditionType',
    width: 120,
    customRender: ({ record }) => {
      const conditionType = record.conditionType;
      let text = '';
      switch (conditionType) {
        case 1:
          text = '个人';
          break;
        case 2:
          text = '部门';
          break;
        case 3:
          text = '其他条件进入此处';
          break;
      }
      return text;
    },
  },
  {
    title: '排序',
    dataIndex: 'sort',
    width: 120,
  },
  {
    title: '个人或部门名称',
    dataIndex: 'conditionName',
  },
  // {
  //   title: '状态',
  //   dataIndex: 'status',
  //   width: 80,
  //   customRender: ({ record }) => {
  //     const status = record.status;
  //     const enable = ~~status === 1;
  //     const color = enable ? 'green' : 'red';
  //     const text = enable ? '启用' : '停用';
  //     return h(Tag, { color: color }, () => text);
  //   },
  // },
  {
    title: '创建时间',
    dataIndex: 'createTime',
    width: 180,
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'keyword',
    label: '查询',
    component: 'Input',
    colProps: { span: 8 },
  },
  // {
  //   field: 'status',
  //   label: '状态',
  //   component: 'Select',
  //   componentProps: {
  //     options: [
  //       { label: '启用', value: 1 },
  //       { label: '停用', value: 0 },
  //     ],
  //   },
  //   colProps: { span: 8 },
  // },
];

export const formSchema: FormSchema[] = [
  {
    field: 'lineType',
    label: '链路类型',
    component: 'Select',
    componentProps: {
      options: [
        { label: '无条件', value: 0 },
        { label: '有条件', value: 1 },
      ],
    },
    required: true,
    colProps: { lg: 24, md: 24 },
  },
  {
    field: 'sort',
    label: '排序',
    component: 'InputNumber',
    required: true,
  },

  {
    field: 'conditionType',
    label: '发起人类型',
    component: 'Select',
    ifShow: ({ values }) => values.lineType === 1,

    componentProps: {
      options: [
        { label: '个人', value: 1 },
        { label: '部门', value: 2 },
        { label: '其他条件', value: 3 },
      ],
    },
  },

  {
    field: 'conditionNo',
    label: 'conditionNo',
  },
  {
    field: 'conditionName',
    label: '发起人名称',
    slot: 'conditionName',
    ifShow: ({ values }) => values.lineType === 1,
  },

  {
    field: 'titleInclude',
    label: '标题包含',
    component: 'Input',
    required: false,
  },

  {
    field: 'items',
    label: '审批人列表',
    slot: 'items',
    colProps: { lg: 24, md: 24 },
  },
];

export const node_columns: VxeGridPropTypes.Columns = [
  {
    title: '审批人',
    field: 'userName',
    align: 'center',
  },

  {
    title: '审批类型',
    field: 'approverType',
    align: 'center',

    formatter: ({ cellValue, row, column }) => {
      const approverType = cellValue;
      let text = '';
      switch (approverType) {
        case 1:
          text = '审批人';
          break;
        case 2:
          text = '知会人';
          break;
      }
      return text;
    },
  },
  {
    align: 'center',
    field: "izMatcheManage",
    title: '匹配上级领导',
    formatter: ({ cellValue, row, column }) => {
      const type = cellValue;
      let text = '';
      switch (type) {
        case 1:
          text = '是';
          break;
        // case 0:
        //   text = '知会人';
        //   break;
      }
      return text;
    },
    width: 90,
  },
  {
    align: 'center',
    title: '排序',
    field: 'sort',
  },
  {
    width: 130,
    title: '操作',
    align: 'center',
    field: '',
    slots: { default: 'action' },
    fixed: 'right',
  },
];

export const node_user_formSchema: FormSchema[] = [
  {
    field: 'userId',
    label: 'userId',
  },
  {
    field: 'approvalSettingLineId',
    label: 'approvalSettingLineId',
  },
  {
    field: 'approvalSettingNodeId',
    label: 'approvalSettingNodeId',
  },

  {
    field: 'approvalSettingId',
    label: 'approvalSettingId',
  },
  {
    field: 'userName',
    label: '审批人名称',
    slot: 'userName',
  },
  {
    field: 'approverType',
    label: '审批类型',
    component: 'Select',
    componentProps: {
      options: [
        { label: '审批人', value: 1 },
        { label: '知会人', value: 2 },
      ],
    },
    required: true,
    // colProps: { lg: 24, md: 24 },
  },
  {
    field: 'izMatcheManageValue',
    label: '是否匹配上级领导',
    component: 'Switch',
  },

  {
    field: 'sort',
    label: '排序',
    component: 'InputNumber',
    required: true,
  },
];
